<template>
		<!-- 社区图片 -->
		<view class="pics">
			<!-- 左侧菜单栏 -->
			<scroll-view class="left" scroll-y>
				<!-- 循环 -->
				<view :class="active===index?'active':''" @click="leftClick(index,item.id)" v-for="(item,index) in pics" :key="item.id">{{item.title}}</view>
			</scroll-view>
			<!-- 左边菜单栏结束 -->
			<!-- 右侧菜单栏 -->
			<scroll-view class="right" scroll-y>
				<view class="item" v-for="item in secondPics" :key ="item.id">
					<image :src="item.img_url" @click="clickPics(item.img_url)"></image>
					<text>{{item.title}}</text>
				</view>
				<text v-if="secondPics.length===0">暂无数据</text>
			</scroll-view>
			<!-- 右侧菜单栏结束 -->
		</view>
</template>

<script>
	export default {
		data() {
			return {
				pics:[],
				active:0,
				// 二级分类
				secondPics:[]
			}
		},
		onLoad() {
			this.getPics()
		},
		methods: {
			// 获取分类标题
			async getPics(){
			const res =	await this.$MyRequest({
					url:"/api/getimgcategory"
				})
				console.log(res)
				this.pics =res.data.message
				this.leftClick(0,this.pics[0].id)
			},
			// 获取右侧数据
			// getRight(){
				
			// },
			// 左侧点击高亮事件
		async leftClick(index,id){
				console.log(index)
				this.active =index
				// 获取右侧数据
				const res =await this.$MyRequest({
					url:"/api/getimages/"+id,
					
				})
				console.log(res)
				this.secondPics =res.data.message
			},
			// 点击预览图片
			clickPics(current){
				// 通过url接受传来的数据
				const urls =this.secondPics.map(item=>{
					// 每一组数据
					return item.img_url
				})
				uni.previewImage({
					// 图片地址
					urls,
					current
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.pics{
		height: 100%;
		display: flex;
		.left{
			width: 200rpx;
			height: 100%;
			border-right:1px solid #eee;
			view{
				height: 60px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top:1px solid #eee;
			}
			.active{
				background: pink;
				color: #fff;
			}
		}
		.right{
			height: 100%;
			width: 520rpx;
			margin: 10rpx auto;
			.item{
				image{
					width: 520rpx;
					height: 520rpx;
					border-radius: 5px;
				}
				text{
					font-size: 30rpx;
					line-height: 60rpx;
				}
			}
		}
	}
</style>